package com.tm.d12_arrays;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 2024/5/25 Cjj 对 Arrays数据存储的对象进行排序 10:24
 */
public class ArrayTest2 {
    public static void main(String[] args) {
        Student[] students = new Student[4];
        students [0] = new Student("蜘蛛精",169.5,23);
        students [1] = new Student("紫霞",163.8,26);
        students [2] = new Student("紫霞",163.8,26);
        students [3] = new Student("至尊宝",167.5,24);

//       Arrays.sort(students);
//        System.out.println(Arrays.toString(students));

       /**按照升高升序**/
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
         /*      if(o1.getHeight()> o2.getHeight()){
                   return 1;
               }else if (o1.getHeight()< o2.getHeight()){
                   return -1;
               }
                return 0;*/

                return Double.compare(o1.getHeight(),o2.getHeight());
            }
        });
        System.out.println(Arrays.toString(students));
    }
}
